#!/usr/bin/enr/python3
# -*- coding: utf-8 -*-
# -------------------------------
# @Author : hurong
# @File : day03.py
# @Time : 2025/3/30 11:00
# -------------------------------
#!/usr/bin/enr/python3
# -*- coding: utf-8 -*-
# -------------------------------
# @Author : hurong
# @File : day03.py
# @Time : 2025/3/28 20:14
# -------------------------------
"""
分支结构：if、elif、else

"""
#
"""
BMI计算器

if……else……

"""

height = float(input('身高(cm)：'))
weight = float(input('体重(kg)：'))
bmi = weight / (height / 100) ** 2
print(f'{bmi = :.1f}')
if bmi < 18.5:
    print('你的体重过轻！')
elif bmi < 24:
    print('你的身材很棒！')
elif bmi < 27:
    print('你的体重过重！')
elif bmi < 30:
    print('你已轻度肥胖！')
elif bmi < 35:
    print('你已中度肥胖！')
else:
    print('你已重度肥胖！')

"""
match 和 case 构造分支结构
Python 3.10 中增加了一种新的构造分支结构的方式，
通过使用match和case 关键字，我们可以轻松的构造出多分支结构。
"""
print(50 * '*')
# 方法一
status_code = int(input('响应状态码: '))
if status_code == 400:
    description = 'Bad Request'
elif status_code == 401:
    description = 'Unauthorized'
elif status_code == 403:
    description = 'Forbidden'
elif status_code == 404:
    description = 'Not Found'
elif status_code == 405:
    description = 'Method Not Allowed'
elif status_code == 418:
    description = 'I am a teapot'
elif status_code == 429:
    description = 'Too many requests'
else:
    description = 'Unknown status Code'
print('状态码描述:', description)

# 方法二：使用match-case语法实现的代码;match-case 适用于python3.10.x以上；python3.9会报错。
status_code = int(input('响应状态码: '))
match status_code:
    case 400: description = 'Bad Request'
    case 401: description = 'Unauthorized'
    case 403: description = 'Forbidden'
    case 404: description = 'Not Found'
    case 405: description = 'Method Not Allowed'
    case 418: description = 'I am a teapot'
    case 429: description = 'Too many requests'
    case _: description = 'Unknown Status Code'
print('状态码描述:', description)
status_code = int(input('响应状态码: '))
print(50 * '*')

match status_code:
    case 400 | 405: description = 'Invalid Request'
    case 401 | 403 | 404: description = 'Not Allowed'
    case 418: description = 'I am a teapot'
    case 429: description = 'Too many requests'
    case _: description = 'Unknown Status Code'
print('状态码描述:', description)

